//
//  HMRecommendPopView.m
//  HowToDo
//
//  Created by Stan on 2017-01-10.
//  Copyright © 2017 KY. All rights reserved.
//

#import "HMRecommendPopView.h"

@interface HMRecommendPopView ()

@property(strong,nonatomic)UILabel *titleLabel;
@property(strong,nonatomic)UILabel *priceLabel;
@property(copy,nonatomic)void(^confirmBlock)();
@property(copy,nonatomic)void(^cancelBlock)();






@end

@implementation HMRecommendPopView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor colorWithHex:0xf1f1f1];
        
        //    添加标题标签
        UILabel *titleLabel = [UILabel hm_labelWithText:@"标题" fontSize:k_FONT_NORMAL colorWithHex:0x565656];
        self.titleLabel = titleLabel;
        titleLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(11);
            make.left.right.offset(0);
        }];
        
        //    添加价格标签
        UILabel *priceLabel = [UILabel hm_labelWithText:@"价格" fontSize:k_FONT_NORMAL color:[UIColor colorWithHex:0x565656] TextAlignment:NSTextAlignmentCenter];
        self.priceLabel = priceLabel;
        [self addSubview:priceLabel];
        [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(titleLabel.mas_bottom).offset(11);
            make.left.right.offset(0);
        }];
        
        //    确定按钮
        UIButton *confirmBtn = [[UIButton alloc]init];
        [self addSubview:confirmBtn];
        confirmBtn.backgroundColor = [UIColor orangeColor];
        [confirmBtn hm_setTitle:@"确定" andTiTleColorWithHex:0xffffff forState:UIControlStateNormal];
        confirmBtn.titleLabel.font = [UIFont systemFontOfSize:k_FONT_NORMAL];
        confirmBtn.layer.cornerRadius = 5.0;
        [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(priceLabel.mas_bottom).offset(14);
            make.left.offset(11);
            make.right.offset(-11);
        }];
        [confirmBtn addTarget:self action:@selector(confirmBtnClick) forControlEvents:UIControlEventTouchUpInside];
        
        //    取消按钮
        UIButton *cancelBtn = [[UIButton alloc]init];
        [self addSubview:cancelBtn];
        cancelBtn.backgroundColor = [UIColor lightGrayColor];
        [cancelBtn hm_setTitle:@"取消" andTiTleColorWithHex:0xf9f9f9 forState:UIControlStateNormal];
        cancelBtn.titleLabel.font = [UIFont systemFontOfSize:k_FONT_NORMAL];
        cancelBtn.layer.cornerRadius = 5.0;
        
        [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(confirmBtn.mas_bottom).offset(14);
            make.left.offset(11);
            make.right.offset(-11);
            make.bottom.offset(-14);
        }];
        
        [cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
        
        [self layoutIfNeeded];
        self.frame = CGRectMake(0, 0, k_SCREEN_WIDTH, 150);
    }
    return self;
}



- (void)cancelBtnClick{
    if(_cancelBlock)
    {
        _cancelBlock();
    }
}

- (void)confirmBtnClick{
    if (_confirmBlock) {
        _confirmBlock();
    }
}

+ (instancetype)initWithFirstLabel:(NSString *)first andSecondLabel:(NSString *)second andConfirmBlock:(void(^)())confirmBlock andCancelBlock:(void(^)())cancelBlock{
    HMRecommendPopView *popView = [[HMRecommendPopView alloc]init];
    popView.titleLabel.text = first;
    popView.priceLabel.text = second;
    
    popView.confirmBlock = confirmBlock;
    popView.cancelBlock = cancelBlock;
    return popView;
}
@end
